package me.kuye.jkuye.plugin.activerecord;

import java.io.Serializable;
import java.util.Map;

import me.kuye.jkuye.helper.DatabaseHelper;

public class Record implements Serializable {
	private Map<String, Object> columns;

	public Record setContainerFactoryByConfigName(String configName) {
		Config config = DatabaseHelper.getConfig(configName);
		if (config == null) {
			throw new IllegalArgumentException(" the config can not be null" + configName);
		}
		processCloumnMap(config);
		return this;
	}

	private void processCloumnMap(Config config) {
		if (columns == null || columns.size() == 0) {
			columns = config.getContainerFactory().getColumnsMap();
		} else {
			Map<String, Object> columnsOld = columns;
			columns = config.getContainerFactory().getColumnsMap();
			columns.putAll(columnsOld);
		}
	}

	public Map<String, Object> getColumns() {
		if (columns == null) {
			if (DatabaseHelper.config == null) {
				columns = DatabaseHelper.brokenConfig.getContainerFactory().getColumnsMap();
			} else {
				columns = DatabaseHelper.config.getContainerFactory().getColumnsMap();
			}
		}
		return columns;
	}

	public Object get(String string) {
		return null;
	}

	public void set(String string, Object value) {
		
	}

	public Record setColumns(Map<String, Object> attrs) {
		return null;
	}
}
